/**
 * 北京中流科技有限公司 版权所有
 * http://www.chinasoa.com.cn
 */
package cn.com.chinasoa.cms.portlet.action;

import java.io.IOException;
import java.util.Map;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

import org.w3c.dom.Element;

import com.x4ee.soa.portal.framework.core.ActionConfig;
import com.x4ee.soa.portal.framework.core.ActionFilter;
import com.x4ee.soa.portal.framework.core.BaseRequestFilter;
import com.x4ee.soa.portal.framework.core.FrameworkConfig;

/**
 * @author 刘洋(liuyang@chinasoa.com.cn)
 * 2007-8-7上午11:56:05
 */
public class OutletCreateActionFilter extends BaseRequestFilter implements
		ActionFilter {

	private FrameworkConfigWraper tFrameworkConfigWraper =null;
	public String process(ActionRequest actionRequest, ActionResponse actionResponse,
			ActionConfig actionConfig) throws PortletException, IOException {
		
		String outletName = actionRequest.getParameter("outletName");		
		String uriName = actionRequest.getParameter("uriName");
		if((outletName!=null)&&(uriName!=null)){
			if(tFrameworkConfigWraper.addOutlet(outletName, uriName)){
				Map frameworkOutletMap = FrameworkConfigWraper.getOutletMapByRenderName(tFrameworkConfigWraper.getXmlConfig(),"ViewIndex");
				actionRequest.getPortletSession().setAttribute(FrameworkConfigWraper.FRAMEWORK_OUTLET_MAP,frameworkOutletMap);
				return FrameworkConfigWraper.DEFAULT;
			}else{
				return FrameworkConfigWraper.ERROR;
			}
		}else{
			return FrameworkConfigWraper.ERROR;			
		}
	}

	public void init(Element tXmlConfig, FrameworkConfig frameworkConfig) throws PortletException {
		super.init(tXmlConfig, frameworkConfig);
		tFrameworkConfigWraper = new FrameworkConfigWraper(tXmlConfig,frameworkConfig);		
	}

}
